package foliotracker.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import foliotracker.Portfolio;
import foliotracker.PortfolioCollection;
import foliotracker.views.IFolioTrackerView;
import foliotracker.views.IPortfolioCollectionView;

import foliotracker.*;

/**
 * Handles actions to do with portfolio collections such as adding and deleting of portfolios.
 */
public class PortfolioCollectionController
{
	private IFolioTrackerView mainView;
	private IPortfolioCollectionView view;
	private PortfolioCollection collection;
	
	public PortfolioCollectionController(IFolioTrackerView mainView, PortfolioCollection collection)
	{
		this.mainView = mainView;
		this.collection = collection;
	}
	
	
	public void setView(IPortfolioCollectionView view)
	{
		this.view = view;
	}
	
	/**
	 * Adds a new portfolio with the specified name and shows its details.
	 * @param name
	 */
	public void addPortfolio(String name)
	{			
		Portfolio p = new Portfolio(name);
		collection.addPortfolio(p);
		mainView.openPortfolioView(p);
	}
	
	/**
	 * Removes the selected portfolio.
	 */
	public void removePortfolio()
	{
		collection.removePortfolio(view.getSelectedPortfolioID());
		
	}
	
	/**symbol
	 * Retrieves the selected portfolio and tells the view to show its details.
	 */
	public void openPortfolio() 
	{
		
		Portfolio p = collection.getPortfolioByID(view.getSelectedPortfolioID());
		mainView.openPortfolioView(p);
	}
	
}

